package net.alteiar.images.filter.elements;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;

import net.alteiar.images.BasicImage;
import net.alteiar.images.filter.IFilter;
import net.alteiar.images.metadata.EntityInfo;

public class ElementFilter extends IFilter {

	private final BasicImage image;

	protected final EntityInfo entity;

	public ElementFilter(EntityInfo entity, BasicImage img) {
		this.entity = entity;
		this.image = img;
	}

	protected void printElement(Graphics2D g2, Point position, int width,
			int height) {
		BufferedImage img = this.image.getImage();
		g2.drawImage(img, position.x, position.y, width, height, null);
	}

	@Override
	public void draw(Graphics2D g2, double zoomFactor) {
		Point position = entity.getPosition();
		int width = entity.getWidth();
		int height = entity.getHeight();

		int x = (int) Math.floor(position.x * zoomFactor) + 1;
		int y = (int) Math.floor(position.y * zoomFactor) + 1;

		int realWidth = (int) (width * zoomFactor);
		int realHeight = (int) (height * zoomFactor);

		printElement(g2, new Point(x, y), realWidth, realHeight);
	}
}
